package orderclient

import (
	"context"
	order "order/kitex_gen/order"

	"github.com/cloudwego/kitex/client"
	"github.com/cloudwego/kitex/client/callopt"
	"order/kitex_gen/order/orderservice"
)

type RPCClient interface {
	KitexClient() orderservice.Client
	Service() string
	AddOrder(ctx context.Context, req *order.AddOrder, callOptions ...callopt.Option) (r *order.AddOrder, err error)
	DeleteOrder(ctx context.Context, req *order.DeleteOrder, callOptions ...callopt.Option) (r *order.DeleteOrder, err error)
	GetOrder(ctx context.Context, req *order.GetOrder, callOptions ...callopt.Option) (r *order.GetOrder, err error)
	UpdateOrder(ctx context.Context, req *order.UpdateOrder, callOptions ...callopt.Option) (r *order.UpdateOrder, err error)
}

func NewRPCClient(dstService string, opts ...client.Option) (RPCClient, error) {
	kitexClient, err := orderservice.NewClient(dstService, opts...)
	if err != nil {
		return nil, err
	}
	cli := &clientImpl{
		service:     dstService,
		kitexClient: kitexClient,
	}

	return cli, nil
}

type clientImpl struct {
	service     string
	kitexClient orderservice.Client
}

func (c *clientImpl) Service() string {
	return c.service
}

func (c *clientImpl) KitexClient() orderservice.Client {
	return c.kitexClient
}

func (c *clientImpl) AddOrder(ctx context.Context, req *order.AddOrder, callOptions ...callopt.Option) (r *order.AddOrder, err error) {
	return c.kitexClient.AddOrder(ctx, req, callOptions...)
}

func (c *clientImpl) DeleteOrder(ctx context.Context, req *order.DeleteOrder, callOptions ...callopt.Option) (r *order.DeleteOrder, err error) {
	return c.kitexClient.DeleteOrder(ctx, req, callOptions...)
}

func (c *clientImpl) GetOrder(ctx context.Context, req *order.GetOrder, callOptions ...callopt.Option) (r *order.GetOrder, err error) {
	return c.kitexClient.GetOrder(ctx, req, callOptions...)
}

func (c *clientImpl) UpdateOrder(ctx context.Context, req *order.UpdateOrder, callOptions ...callopt.Option) (r *order.UpdateOrder, err error) {
	return c.kitexClient.UpdateOrder(ctx, req, callOptions...)
}
